﻿<template>
    <full-screen-dialog
        :title="titleMap[mode]"
        v-model="visible"
        :width="600"
        destroy-on-close
        :close-on-click-modal="false"
        :before-close="handleBeforeClose"
    >
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >
        <el-card >
            <template #header>
            <div class="card-header">
                <span>银行账户</span>
            </div>
            </template>
            
            <div  style="background-color:#D4D7DE;padding:5px">对公银行账户</div>
            <el-divider />
           
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="公司名称" prop="pubCompanyName">
                        <el-input v-model="entityObj.pubCompanyName" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="对公银行账号" prop="pubBankAccount">
                        <el-input v-model="entityObj.pubBankAccount" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="对公开户行" prop="pubOpenBank">
                        <el-input v-model="entityObj.pubOpenBank" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>

            <div  style="background-color:#D4D7DE;padding:5px">对私银行账户</div>
            <el-divider />
           
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="姓名" prop="priUserName">
                        <el-input v-model="entityObj.priUserName" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="对私银行账号" prop="priBankAccount">
                        <el-input v-model="entityObj.priBankAccount" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="22">
                    <el-form-item label-width="120px" label="对私开户行" prop="priOpenBank">
                        <el-input v-model="entityObj.priOpenBank" type="text" style="width: 100%"/>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-card>
            
           
        </el-form>
        <template #footer>
            <el-button @click="handleBeforeClose">取 消</el-button>
            <el-button
                v-if="mode != 'show'"
                type="primary"
                :loading="isSaveing"
                @click="submit()"
            >确 定</el-button>
        </template>

        <template>
            <el-dialog
                v-model="supplierState"
                title="选择供应商"
                :width="1300"
                :center="true"
                append-to-body
                style="height: 480px"
            >
                <el-row>
                    <sc-supplier-choice ref="scSupplierChoice" :defaultQueryList="{brandCode:entityObj.brandCode}"></sc-supplier-choice>
                </el-row>
                <template #footer>
                    <el-button @click="supplierState = false">取 消</el-button>
                    <el-button type="primary" :loading="isSaveing" @click="setSupplierChoice">确定</el-button>
                </template>
            </el-dialog>
        </template>
    </full-screen-dialog>
</template>



<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            mode: "Add",
            titleMap: {
                Add: "新增",
                Edit: "设置银行账户信息",
                Show: "查看",
            },
            entityObj: {
                supplierIds:[],
                suppliers: [],
            },
            supplierState: false,
            applyOrderState: false,
            storeState: false,
            queryList: {},
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            //验证规则
            rules: {},
            supplierId:0,
           
        };
    },
    
    methods: {
        //显示=
        async open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        //表单提交方法
        submit() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    try {
                        this.entityObj.SupplierId=this.supplierId;
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "bankInfo/updateBankInfo",
                                { ...this.entityObj }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                            this.isSaveing = false;
                        }
                    } catch (error) {
                        this.loading = false;
                        this.isSaveing = false;
                        return false;
                    }
                }
            });
        },
        //表单注入数据
        async setData(data) {
            console.log(data)
            this.supplierId=data.supplierId;
            const returnValue = await this.$API.auth.GetProcessApi.get(
                `bankInfo/${data.supplierId}/supplier`,{}
            );
            if (returnValue.status == 200) { 
                this.entityObj = {
                    ...returnValue.response,
                };
            }
        },
    },
    async mounted() {
    },
};
</script>

<style></style>
